package basic

class Solution {
    fun balancedStringSplit(s: String): Int {
        val arr: CharArray = s.toCharArray()
        var count: Int = 0
        var rCount: Int = 0
        var lCount: Int = 0

        for (c in arr) {
            if (c.equals('R')) {
                rCount++
            } else {
                lCount++
            }
            // what is and

            if ((rCount != 0 && lCount != 0) && rCount == lCount) {
                count++;
                lCount = 0;
                rCount = 0;
            }
        }
        return count
    }
}